require('babel-polyfill');
import Vue from 'vue';
import Index from './Index.vue';
import router from './router';
import store from './store/store.js';
import { VTable } from 'vue-easytable';
import vSelect from 'vue-select';
import ECharts from 'vue-echarts';
import 'echarts/lib/chart/bar';
import 'echarts/lib/component/tooltip';
import VueFlatPickr from 'vue-flatpickr-component';
import VeeValidate, { Validator } from 'vee-validate';
import zh from 'vee-validate/dist/locale/zh_CN';
import axios from 'axios';
import CONFIG from 'common/constants/config';
import NProgress from 'nprogress';
import Imodal from '@/common/components/assembly/Imodal';
import InputFile from '@/common/components/assembly/InputFile';
import Pagination from '@/common/components/assembly/Pagination';

axios.defaults.baseURL = CONFIG.getBaseURL();
// import userFactory from '@/common/factory/userFactory';

// router.beforeEach((to, from, next) => {
//   let role, typeArr = [1, 2];
//   if (sessionStorage.userInfo) {
//     role = parseInt(JSON.parse(sessionStorage.userInfo).role);
//     if (typeArr.indexOf(role) !== -1) {
//       next();
//     } else {
//       next();
//       // location.href = '/#/';
//     }
//   }
// });
// 当路由进入前
router.beforeEach((to, from, next) => {
  // 每次切换页面时，调用进度条
 NProgress.start();
 // 这个一定要加，没有next()页面不会跳转的。这部分还不清楚的去翻一下官网就明白了
  next();
});
// 当路由进入后：关闭进度条
router.afterEach(() => {
  setTimeout(() => {
    NProgress.done();
  }, 300);
});
NProgress.configure({
  easing: 'ease-in',  // 动画方式
  speed: 800,  // 递增进度条的速度
  showSpinner: false, // 是否显示加载ico
  trickleSpeed: 200, // 自动递增间隔
  minimum: 0.3 // 初始化时的最小百分比
});

Validator.localize('zh_CN', zh); // 使用中文语言
const config = {
  errorBagName: 'errors', // change if property conflicts.
  fieldsBagName: 'fieldBags',  // 报冲突时 可自定义修改字段名称
  delay: 0, // 错误提示的延迟时间
  strict: true, // 没有设置规则的表单不进行校验，
  enableAutoClasses: false,
  locale: zh, // 对语言（中文）的配置
  classNames: {
    touched: 'touched', // the control has been blurred
    untouched: 'untouched', // the control hasn't been blurred
    valid: 'valid', // model is valid
    invalid: 'invalid', // model is invalid
    pristine: 'pristine', // control has not been interacted with
    dirty: 'dirty' // control has been interacted with
  },
  events: 'blur'
};

Vue.use(VeeValidate, config);

Vue.component(VTable.name, VTable);

Vue.component('v-select', vSelect);

Vue.component('v-chart', ECharts);

Vue.component('flat-pickr', VueFlatPickr);

Vue.component('i-modal', Imodal);

Vue.component('input-file', InputFile);

Vue.component('pagination', Pagination);
// 全局引用jquery

window.$ = require('jquery');
new Vue({
  el: '#app',
  router,
  template: '<Index/>',
  components: { Index },
  store,

  beforeMount () {
    // 初始化全局弹框,loader
    // window.showLoader();
  },

  mounted () {
    this.init();
  },

  methods: {
    /**
     * 初始化
     */
    init () {
      document.getElementById('mask').className = 'hide';
    },

    initModals () {

    }
  }
});

